package com.sky.controller.admin;

import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.OrderComparator;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Api(tags = "管理端-订单接口")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;


    //订单数量统计
    @GetMapping("/statistics")
    @ApiOperation("订单数量统计")
    public Result<OrderStatisticsVO> OrderQuantityStatistics(){
        OrderStatisticsVO orderStatisticsVO= orderService.Statistics();
        return Result.success(orderStatisticsVO);
    }

    //订单查询
    @GetMapping("/details/{id}")
    @ApiOperation("订单查询")
    public Result<OrderVO> details(@PathVariable Long id) {
        log.info("订单查询:{}",id);
        OrderVO orderVO = orderService.selectOrder(id);
        return Result.success(orderVO);
    }

    //订单搜索
    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> OrdersSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult= orderService.OrdersSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    //接单
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result TakeOrders(@RequestBody OrdersConfirmDTO orders){
        log.info("接单:{}",orders);
        orderService.takeOrders(orders);
        return Result.success();
    }

    //派送
    @PutMapping("/delivery/{id}")
    public Result deliveryOrders(@PathVariable Long id){
        orderService.deliverOrders(id);
        return Result.success();
    }

    //完成订单
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result CompleteOrders(@PathVariable Long id){
        orderService.CompleteOrders(id);
        return Result.success();
    }

    //取消订单
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.CancelOrders(ordersRejectionDTO);
        return Result.success();
    }

    //拒单
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejectionById(ordersRejectionDTO);
        return Result.success();
    }
}
